package com.cgl.service.imp;

import com.cgl.mapper.UserActionMapper;
import com.cgl.pojo.User;
import com.cgl.pojo.UserAction;
import com.cgl.service.UserActionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.time.LocalDateTime;
@Service
public class UserActionServiceImp implements UserActionService {
    @Autowired
    private UserActionMapper userActionMapper;
    @Override
    public int addUserVisitAction(String ip) {
        UserAction action = UserAction.addUserAction(ip,"visit", LocalDate.now(), LocalDateTime.now());
        int result = userActionMapper.addUserAction(action);
        return result;
    }

    @Override
    public int[] getLastAllUserNumber(int days) {
        int[] result = new int[days];
        //获得近7天的的访问量
        for (int i = 0; i < days; i++) {
            LocalDate date = LocalDate.now().minusDays(i);
            String day = date.toString();
            int count = userActionMapper.getCountByDay(day);
            result[days-i-1] = count;
        }
        return result;
    }
}
